<template>
  <div>
      <div >
          <el-row class="Search-on">
              <el-col :span="10" >
                  <el-input v-model="username" placeholder="请输入搜索内容"></el-input>
              </el-col>
              <el-col :span="3" >
                  <el-button type="success" icon="el-icon-search" @click="search()">查询</el-button>
              </el-col>

          </el-row>
      </div>
<!--    <div>-->
<!--      <el-input-->
<!--          size="small"-->
<!--          class="addPosInput"-->
<!--          placeholder="添加"-->
<!--          suffix-icon="el-icon-plus"-->
<!--          @keydown.enter.native="addPosition"-->
<!--          v-model="addManager.username">-->
<!--      </el-input>-->
<!--      <el-button-->
<!--          size="small"-->
<!--          icon="el-icon-plus" type="primary" @click="addPosition">添加-->
<!--      </el-button>-->
<!--    </div>-->
    <div class="postMaMa">
      <el-table
          size="small"
          stripe
          border
          :data="allManager"
          style="width: 70%">
        <!--        prop为data数组的列名-->
        <el-table-column
            prop="id"
            label="序号"
            width="50"
            >
        </el-table-column>
        <el-table-column
            prop="username"
            label="名字"
            width="180"
           >
        </el-table-column>
        <el-table-column
            prop="password"
            label="密码"
            width="180"
            >
        </el-table-column>
        <el-table-column
            prop="num"
            label="登录次数"
            >
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template slot-scope="scope">
            <el-button
                size="mini"
                @click="showEditView(scope.$index, scope.row)">编辑
            </el-button>
            <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.$index, scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          background
          @current-change="currentChange"
          layout="sizes,prev, pager, next, jumper, ->, total"
          :page-sizes="[7, 14, 21, 28]"
          :page-size="size"
          :total="total">

      </el-pagination>
    </div>
    <el-dialog
        title="编辑信息"
        :visible.sync="dialogVisible"
        width="30%">
      <div>
        <!--        名称-->
        <el-tag>用户名称</el-tag>
        <!--        编辑内容-->
        <el-input v-model="updatePos.username" class="updatePosInput"></el-input>
      </div>
      <span slot="footer" class="dialog-footer">
    <el-button size="small" @click="dialogVisible = false">取 消</el-button>
    <el-button size="small" type="primary" @click="doUpdate">确 定</el-button>
  </span>
    </el-dialog>
  </div>

</template>

<script>
export default {
  name: 'ManageUsers',
  data() {
    return {
      total: 0,
      size: 0,
      currentPage:1,
      username:'',
      addManager: {
        id: 0,
        username: '',
        password: '',
        num: 0,
        gmtCreate: '',
        gmtModified:'',
        deleted:0,
        //想要添加的管理员名称
      },
      manager:[],
      allManager: [],//列表的数组
      dialogVisible: false,//弹出框
      // multipleSelection: [],

      updatePos: {//编辑内容
        username: '',
        password: '',
        state: 0,
        loginNum: 0
      },
      delManager: {
        username: '',
        password: '',
        state: 0,
        loginNum: 0
      },
    }
  },
      methods: {
        // handleSelectionChange(val){
        //   this.multipleSelection =val;
        // },
        currentChange(currentPage){
          this.currentPage = currentPage;
          this.initPositions();
        },
        doUpdate() {
          this.putRequest('/manager/all', this.updatePos).then(resp => {//put改get不报错，但无法更改
            if (resp) {
              this.initPositions();
              this.dialogVisible = false;//添加框内容清空
            }
          })
        },
        // addPosition() {//添加
        //   if (this.addManager.username) {
        //     this.postRequest('/manager/all', this.pos).then(resp => {
        //       if (resp) {
        //         this.initPositions();
        //       }
        //     })
        //   } else {
        //     this.$message.error('输入短链接不能为空');
        //   }
        // },
        showEditView(index, data) {//编辑
          //this.updatePos = data;
          Object.assign(this.updatePos, data);//数据拷贝
          // this.updatePos.state=0;//传回去的参数不变
          // this.updatePos.loginNum=0;
          this.dialogVisible = true;
        },
        // handleDelete(index, data) {//删除
        //   this.$confirm('此操作将永久删除该[' + data.name + ']数据, 是否继续?', '提示', {
        //     confirmButtonText: '确定',
        //     cancelButtonText: '取消',
        //     type: 'warning'
        //   }).then(() => {
        //     this.deleteRequest('url' + data.shortlink).then(resp => {
        //       if (resp) {
        //         this.initPositions();
        //       }
        //     })
        //   }).catch(() => {
        //     this.$message({
        //       type: 'info',
        //       message: '已取c消删除'
        //     });
        //   });
        // },
        initPositions() {//接口调用
          // this.$message.success("0000")
          this.getRequest("/manager/all/"+this.currentPage).then((resp) => {
            if (resp) {
              this.allManager = resp.data.records;
              this.total = resp.data.total;
              this.size = resp.data.size;
            }
          })
        },
      search() {
          this.postRequest('/manager/select?username='+this.username).then(resp => {
              if (resp) {
                  this.allManager = resp;
              }
          })
      }
      },
      mounted() {
        this.initPositions();
      }


}
</script>

<style scoped>
.addPosInput {
  width: 300px;
  margin-right: 8px;
}
.Search-on {
    width: 1200px;
    /*margin-right: 50px;*/
    left: 26%;
}

.postMaMa {
  margin-top: 10px;
  margin-left: 350px;
}

.updatePosInput {
  width: 280px;
  margin-left: 8px;
}
</style>